﻿#include "stdafx_logm.h"

namespace LOGM
{
	ViewLog::ViewLog(QWidget *parent) :QDockWidget(parent),ui(new DockWidget)
	{
		ui->setupUi(this);
		//data=data_;
		this->connect(LogSave::instance(),SIGNAL(LogChanged(QtMsgType,QString)),this,SLOT(UpdateLogData(QtMsgType,QString)));
		ui->textEdit->setFontPointSize(15);
		ui->textEdit->setFontWeight(QFont::Bold);
	}

	ViewLog::~ViewLog()
	{
		delete ui;
	}
	
	void ViewLog::UpdateLogData(QtMsgType log_type, const QString &msg)
	{
	 
		switch(log_type)
		{
		case QtDebugMsg:
			ui->textEdit->setTextColor(Qt::black);
			break;

		case QtWarningMsg:
			ui->textEdit->setTextColor(Qt::green);
			break;

		case QtCriticalMsg:
			ui->textEdit->setTextColor(Qt::red);
			break;

		case QtFatalMsg:
			ui->textEdit->setTextColor(Qt::blue);
			abort();
		}

		ui->textEdit->append(msg);	
	}

	void DockWidget::setupUi(QDockWidget *DockWidget)
    {
        if (DockWidget->objectName().isEmpty())
            DockWidget->setObjectName(QString::fromUtf8("DockWidget"));
        DockWidget->resize(1600, 900);
        dockWidgetContents = new QWidget();
        dockWidgetContents->setObjectName(QString::fromUtf8("dockWidgetContents"));
		gridLayout = new QGridLayout(dockWidgetContents);
		gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
        textEdit = new QTextEdit(dockWidgetContents);
        textEdit->setObjectName(QString::fromUtf8("textEdit"));
        textEdit->setGeometry(QRect(0, 0, 1200, 400));
		gridLayout->addWidget(textEdit, 0, 0, 1, 1);
        DockWidget->setWidget(dockWidgetContents);

        retranslateUi(DockWidget);

        QMetaObject::connectSlotsByName(DockWidget);
    } // setupUi

    void DockWidget::retranslateUi(QDockWidget *DockWidget)
    {
        DockWidget->setWindowTitle(QApplication::translate("DockWidget", "DockWidget", 0, QApplication::UnicodeUTF8));
    } // retranslateUi
}